﻿using MyData.Data.Repository;
using MyData.Models;
using MyDomain;
using MyRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyRepository
{
   public class MobileRepository : RepositoryBase<Mobile>, IMobileRepository
    {
        public Guid SaveMobile(Mobile mobile)
        {
            using (var db = NewDB())
            {
                var model = db.Query<Mobile>().FirstOrDefault(c=>c.ImeiNum==mobile.ImeiNum);
                if (mobile == null)
                {
                    mobile.Id = Guid.NewGuid();
                    db.Insert<Mobile>(mobile);
                    return mobile.Id;
                }
                model.CreatedTime = DateTime.Now;
                db.Update<Mobile>(model);
                return model.Id;
            }

        }
    }
}
